package com.project.collectAPI.comm;

import org.apache.commons.io.FileUtils;
import org.jsoup.Connection;
import org.jsoup.Jsoup;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;

/**
 * 抓图下载工具类
 */
public class SpiderImagesTool {

    //ajax主机IP地址
    public static final String ServerIP= Constant.ServerIP;

    //当前抓取的店铺名称
    public static final String StoreName="大润发代购（湛江赤坎店）";

    public static String userAgentString="\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF XWEB/6945\"";

    /**
     * 抓取图片类
     */
    public static void downLoadImages(String imageUrl,String imageName,String imagePath) throws IOException {
        //Jsoup工具类
        Connection.Response response= Jsoup.connect(imageUrl)
                .userAgent(userAgentString)
                .ignoreContentType(true)
                .execute();
        ByteArrayInputStream stream=new ByteArrayInputStream(response.bodyAsBytes());
        //org.apache.commons.io.FileUtil
        //FileUtils.copyInputStreamToFile(stream,new File("H://客户网站//美团爬虫//meituan//"+imageName+".png"));
        FileUtils.copyInputStreamToFile(stream,new File(imagePath+imageName));
    }



}
